package android.longs.study.home.service;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSON;
import net.sf.json.JSONSerializer;

import android.longs.study.base.ResponeModel;
import android.longs.study.home.servlet.dao.MobleHomeDao;
import android.longs.study.home.servlet.dao.MobleHomeDaoImple;
import android.longs.study.home.servlet.model.MobleHomeModel;

public class MobleHomeService {

    private MobleHomeDao mHomeDao = new MobleHomeDaoImple();
    public String queryAllModels(HttpServletRequest request) {
	Integer firstNumber=0;
	try {

	    String first = request.getParameter("first");
	    if (first==null || first.equals("")) {
		first = "0";
	    }
	    firstNumber = Integer.valueOf(first);

	} catch (Exception e) {
	    firstNumber=0;
	}



	List<MobleHomeModel> queryAll = mHomeDao.queryAll(firstNumber);


	ResponeModel responeModel = new ResponeModel();
	if (queryAll==null) {
	    responeModel.message ="加载失败";
	    responeModel.code = "1001";
	}else{

	    responeModel.content = queryAll;
	    responeModel.message ="加载成功";
	    responeModel.code = "1000";

	}
	String string = JSONSerializer.toJSON(responeModel).toString();


	return string;
    }

    public String queryAllModels() {
	List<MobleHomeModel> queryAll = mHomeDao.queryAll();


	ResponeModel responeModel = new ResponeModel();
	if (queryAll==null) {
	    responeModel.message ="加载失败";
	    responeModel.code = "1001";
	}else{

	    responeModel.content = queryAll;
	    responeModel.message ="加载成功";
	    responeModel.code = "1000";

	}
	String string = JSONSerializer.toJSON(responeModel).toString();


	return string;
    }
}
